from abc import ABCMeta
from os.path import basename, dirname, join, realpath
from typing import Dict

from mg_app_framework import AppConfigBasic, AppType


class ConfigStore(AppConfigBasic):
    # ==================== DON'T MODIFY THE CODE BETWEEN COMMENT LINE ====================

    work_dir = dirname(dirname(dirname(realpath(__file__))))
    app = basename(dirname(realpath(__file__)))
    log_path = join(work_dir, "log", app + ".log")
    uuid_path = join(work_dir, ".appid")

    def get_module_dir(self):
        return dirname(realpath(__file__))

    def get_log_path(self):
        return self.log_path

    def get_uuid_path(self):
        return self.uuid_path

    def get_data(self):
        return self.data

    # ==================== DON'T MODIFY THE CODE BETWEEN COMMENT LINE ====================

    data = {
        "app_group": "测试组件",
        "app_name": "MES上位机控制系统",
        "app_version": "0.0.1",
        "app_module_name": "prod_ctrl_service",
        "app_type": AppType.user,
        "config_create": True,
        "data": {},
    }

    def get_admin_host(self):
        return "192.168.20.191"

    def get_app_port(self):
        return 30088

    def connect_admin(self):
        return True


class RedisConfigBasic(metaclass=ABCMeta):
    def get_redis_host(self):
        return "192.168.20.229"

    def get_redis_port(self):
        return 6379

    def get_redis_username(self):
        pass

    def get_redis_password(self):
        return "realtech@123"

    def reconnect_interval(self):
        """
        :return:重连redis时间间隔, 默认 5 秒

        """
        return 5

    def get_redis_conn_pool_config(self) -> Dict:
        return {"socket_connect_timeout": 5, "max_connections": 50}
